﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Script.Serialization;
using System.Collections;
using System.IO;
using System.Data;

namespace 税控接口.Common
{
    class handleJSON
    {
        #region 反序列化对象
        /// <summary>
        /// 反序列化对象
        /// </summary>
        /// <param name="json"></param>
        /// <returns></returns>
        public static Dictionary<string, object> Deserialize(string json)
        {
            var js = new JavaScriptSerializer();
            js.MaxJsonLength = Int32.MaxValue; //取得最大数值
            return js.Deserialize<Dictionary<string, object>>(json);
        }

        public static T Deserialize<T>(string json)
        {
            var js = new JavaScriptSerializer();
            js.MaxJsonLength = Int32.MaxValue; //取得最大数值
            return js.Deserialize<T>(json);
        }
        public static Model.ResultJson DeserializeResult(string json)
        {
            var result = new Model.ResultJson();
            var dic = Deserialize(json);
            result.result = dic["result"].ObjToInt();
            result.resultdetail = dic["resultdetail"].ObjToString();
            result.value = dic;
            if (result.result != 1)
            {
                if (result.resultdetail.IndexOf("登陆信息已经过期") > 0)
                { var f = new FrmLogin(); f.ShowDialog(); }
            }
            return result;
        }

        #endregion

        #region 序列化对象
        /// <summary>
        /// 序列化对象
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public static string Serialize(object obj)
        {
            var js = new JavaScriptSerializer();
            js.MaxJsonLength = Int32.MaxValue; //取得最大数值
            return  js.Serialize(obj);
        }
        #endregion

    }


}
